package responseHelper

import (
	"gitee.com/tym_hmm/go-helper/StringHelper"
	"net/http"
)

/**
响应json输出
*/
func ResponseJson(writer http.ResponseWriter, code int, message string, data interface{}) int  {
	responseJson := make(map[string]interface{})
	responseJson["code"] = code
	responseJson["message"] = message
	if data != nil {
		responseJson["data"] = data
	} else {
		responseJson["data"] = map[string]string{}
	}
	jsonStr, _ := StringHelper.MapToJson(responseJson)

	writer.Header().Set("Content-Type", "application/json;charset=utf-8")
	ints, _ := writer.Write([]byte(jsonStr))
	return ints
}
